package com.delicious.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.delicious.dao.impl.MessageDaoImpl;
import com.delicious.entity.Message;

public class MessageListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int pageNum = 1;
		if(request.getParameter("pageNum")!=null && !request.getParameter("pageNum").isEmpty()){
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		}
		int pageSize = 3 ;
		List<Message> list = new MessageDaoImpl().getMessageList(pageNum,pageSize);
		
		int rows = new MessageDaoImpl().getMessageList(0, 0).size();
		int totalPage = (int)Math.ceil((double)rows/pageSize);
		
		request.setAttribute("msg", list);
		request.setAttribute("pageNum", pageNum);
		request.setAttribute("totalPage", totalPage);
		
		request.getRequestDispatcher("message.jsp").forward(request, response);
	}

}
